import { http, getUrl } from "./http";

interface StorageUriParam {
  storageUri: string;
}

interface EntityNameParam {
  entityName: string;
}

const api = {
  login: (param: object) => http("post", "login", param),
  uploadAvatar: () => getUrl("upload/avatar"),
  signUp: (param: object) => http("post", "user/create", param),
  modifyUser: (param: object) => http("put", "user/modify", param),
  modifyPassword: (param: object) => http("put", "user/modifyPassword", param),
  getUsers: (param: object) => http("get", "user", param),

  // storage
  getStorageUri: (param?: object) => http("get", "storage/storageUri", param),
  getStorage: (param?: object) => http("get", "storage", param),
  getStorageByStorageUri: (storageUri: string) =>
    http("get", `storage/${storageUri}`),
  addStorage: (param: object) => http("post", "storage/add", param),
  editStorage: (param: StorageUriParam) =>
    http("put", `storage/${param.storageUri}`, param),
  deleteStorage: (param: StorageUriParam) =>
    http("delete", `storage/${param.storageUri}`, param),

  // entity
  getEntity: (param?: object) => http("get", "entity", param),
  getEntityByEntityName: (entityName: string) =>
    http("get", `entity/${entityName}`),

  addEntity: (param: object) => http("post", "entity/add", param),
  editEntity: (param: object, entityName: string) =>
    http("put", `entity/${entityName}`, param),
  deleteEntity: (param: EntityNameParam) =>
    http("delete", `entity/${param.entityName}`, param),
};

export default api;
